package com.txy.domain.strategy.service.rule.tree.impl;

import com.txy.domain.strategy.model.vo.RuleLogicCheckTypeVO;
import com.txy.domain.strategy.repository.IStrategyRepository;
import com.txy.domain.strategy.service.rule.tree.ILogicTreeNode;
import com.txy.domain.strategy.service.rule.tree.factory.DefaultTreeFactory;
import com.txy.types.common.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component("rule_luck_award")
public class RuleLuckAwardLogicTreeNode implements ILogicTreeNode {
    @Resource
    private IStrategyRepository repository;

    @Override
    public DefaultTreeFactory.DecisionEngineRes logic(Long strategyId, String userId, Integer awardId, String ruleValue) {
        log.info("规则过滤-规则树-rule_luck_award开始: strategyId={}, userId={}", strategyId, userId);
        String[] split = ruleValue.split(Constants.COLON);
        Integer a = Integer.valueOf(split[0]);
        String b = split.length > 1 ? split[1] : "";

        log.info("规则过滤-规则树-rule_luck_award接管返回兜底奖品: strategyId={}, userId={}, ruleValue: {}", strategyId, userId, b);
        // 返回默认奖品
        return DefaultTreeFactory.DecisionEngineRes.builder()
                .ruleLogicCheckTypeVO(RuleLogicCheckTypeVO.TAKE_OVER)
                .awardResClass(DefaultTreeFactory.AwardResClass.builder()
                        .awardId(a).awardValue(b).build()).build();
    }
}
